﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RemoveFunction
{
    internal class sql
    {
        const string sqlconn = "Data Source=szxdt.tpddns.cn;Initial Catalog=demo;User Id=sa;Password=szxdt@123456;";
        public static DataTable SqlGetDT(string CommandText,string conntext= sqlconn)
        {
            using (SqlConnection conn = new SqlConnection(conntext))
            {
                SqlDataAdapter sda = new SqlDataAdapter(CommandText, conn);
                DataSet ds = new DataSet();
                sda.Fill(ds, "Table");
                return ds.Tables["Table"];
            }
        }
        /// <summary>
        /// 执行修改
        /// </summary>
        /// <param name="CommandText"></param>
        /// <param name="Connection"></param>
        /// <returns></returns>
        public static int SqlRevision(string commandText, string conntext = sqlconn)
        {

            using (SqlConnection conn = new SqlConnection(sqlconn))
            {
                SqlCommand cmd = new SqlCommand(commandText, conn);
                if (conn.State != ConnectionState.Open)
                    conn.Open();
                cmd.Connection = conn;
                cmd.CommandText = commandText;
                int recordsAffected = cmd.ExecuteNonQuery();
                return recordsAffected;
            }

        }
    }
}
